<?php require VIEW_PATH."/header.php";?>
<body>
  <link rel="stylesheet" href="Public/org/kindeditor/themes/default/default.css" />
  <script src="Public/org/kindeditor/kindeditor.js"></script>
  <script src="Public/org/kindeditor/lang/zh_CN.js"></script>
  <link rel="stylesheet" href="{{__VIEW__}}/Goods/edit.css" />
<form method="post" enctype="multipart/form-data">
<input type="hidden" name="goods_id" value="{{$data['goods_id']}}">
<!-- 面板切换 -->
<div class="hd-tab">
    <ul class="hd-tab-menu">
        <li lab="base" class="active">
            <a> 基本设置 </a>
        </li>
        <li lab="shop_pic">
            <a>商品图集 </a>
        </li>
        <li lab="shop_value">
            <a>商品属性 </a>
        </li>
        <li lab="shop_detail">
            <a>商品详情 </a>
        </li>
    </ul>
    <div class="hd-tab-content">
        <div lab="base" class="hd-tab-area">            
                <table class="hd-table hd-table-form hd-form">
                    <thead>
                    <tr>
                        <td colspan="2">添加商品</td>
                    </tr>
                    </thead>
                    <tbody>
                    <tr>
                        <th>父级</th>
                        <td>
                            <select name="cat_id">
                                {{foreach from="$catData" value="$field"}}
                                <option value="{{$field['cat_id']}}">{{$field['_name']}}</option>
                                {{endforeach}}              
                            </select>
                        </td>
                    </tr>
                    <tr>
                        <th>商品类型</th>
                        <td>
                            <select name="type_id">
                            {{foreach from="$shopType" value="$field"}}
                                <option value="{{$field['id']}}">{{$field['type_name']}}</option>
                            {{endforeach}}
                            </select>
                        </td>
                    </tr>
                    <tr>
                        <th>商品名称</th>
                        <td>
                            <input type="text" name="goods_name" value="{{$data['goods_name']}}" class="hd-w300">
                        </td>
                    </tr>
                   <tr>
                        <th>货号</th>
                        <td>
                            <input type="text" name="goods_sn" value="{{$data['goods_sn']}}" class="hd-w300">
                        </td>
                    </tr>
                    <tr>
                        <th>单位</th>
                        <td>
                            <input type="text" name="unit" value="{{$data['unit']}}" class="hd-w300">
                        </td>
                    </tr>
                    <tr>
                        <th>品牌</th>
                        <td>
                        <select name="brand_id">
                        {{foreach from="$brandData" value="$field"}}
                            <option value="{{$field['id']}}">{{$field['name']}}</option>
                        {{endforeach}}
                        </select>
                        </td>
                    </tr>
                    <tr>
                        <th>点击数</th>
                        <td>
                        

                            <input type="text" name="click" value="{{$data['click']}}" class="hd-w300">
                        </td>
                    </tr>
                    <tr>
                        <th>列表页图</th>
                        <td>
                        {{if value="$data['list_pic']"}}
                        <img src="{{$data['list_pic']}}" style="width: 50px">
                        {{endif}}
                            <input type="hidden" name="list_pic" value="{{$data['list_pic']}}">
                            <input type="file" name="list_pic" class="hd-w300" style="display: inline-block;">
                        </td>
                    </tr>
                    <tr>
                        <th>缩略图</th>
                        <td>
                        {{if value="$data['thumb_pic']"}}
                        <img src="{{$data['thumb_pic']}}" style="width: 50px">
                        {{endif}}
                            <input type="hidden" name="list_pic" value="{{$data['thumb_pic']}}">
                           <input type="file" name="thumb_pic" class="hd-w300" style="display: inline-block;">
                        </td>
                    </tr>
                    <tr>
                        <th>商品关键词</th>
                        <td>
                            <input type="text" name="keyword" value="{{$data['keyword']}}" class="hd-w300">
                        </td>
                    </tr>
                    <tr>
                        <th>商品描述</th>
                        <td>
                            <textarea name="description" value="{{$data['description']}}" class="hd-w300 hd-h100"></textarea>
                        </td>
                    </tr>                    
                    </tbody>
                </table>
                
        </div>
         <!-- 商品图集 -->
        <div lab="shop_pic" class="hd-tab-area">
            <ul class="picList">
            {{foreach from="$pics" value="$img"}}
                <li class="picLi" id="picLi{{$img['id']}}">
                    <img src="{{$img['small_pic']}}"  style="width:100px;margin-left:0px;">
                    <section id="liDel">
                        <span onclick="delPic({{$img['id']}})" class="btn btn-danger">
                            x
                        </span>
                    </section>
                </li>                
            {{endforeach}}
            </ul>
            <table>
                <tr>
                    <td style="height: 40px;">
                        <input type="file" name="pics[]" style="display:inline-block">
                        <button type="button" onclick="addPic(this)" style="display:inline-block;box-shadow: 0 0 5px #ccc;border-radius: 0;font-weight: bold;" class="btn btn-warning">＋</button>
                    </td>
                </tr>
            </table>
        </div>
        <!-- 商品图集end -->

        <!-- 商品属性 -->
        <div lab="shop_value" class="hd-tab-area">
        
           <table class="hd-table hd-table-form hd-form">
            <thead>
                <tr>
                    <td colspan="2">商品属性设置</td>
                </tr>
            </thead>
            <tr>
                <th style="width:300px;text-align: rigth;">商品类型</th>
                <td>
                    <select name="type_id" onchange="editAttrList(this)">
                    <option value="">===请选择商品类型===</option>
                    {{foreach from="$shopType" value="$field"}}                        
                        <option value="{{$field['id']}}">{{$field['type_name']}}</option>       
                    {{endforeach}}
                    </select>
                    <!-- 温馨提示 -->
                    <span style="font-weight: bold;span">
                        <label style="color:red;">*</label>
                     &nbsp;温馨提示，请选择类型后，根据需要填写商品属性
                    </span>
                    <!-- 温馨提示end --> 
                </td>
            </tr>
            <!-- 内容区 -->
            <tr>
                <td colspan="2" style="padding:0;margin: 0;">
                    <p style="background: #ec971f;height: 10px;padding:0;margin: 0;"></p>
                    <!-- 内容插入表单 -->
                    <table id="attr_list" class="hd-table hd-table-form hd-form">

                    </table>
                    <!-- 内容插入表单end -->
                </td>
            </tr>
            <!-- 内容区end -->
        </table> 
        </div>
        <!-- 商品属性end -->

        <!-- 商品详情 -->
        <div lab="shop_detail" class="hd-tab-area">
            <table class="hd-table hd-table-form hd-form">
                <thead>
                    <tr>
                        <td colspan="2">商品详情</td>
                    </tr>
                </thead>
                <tr>
                    <th>商品详情</th>
                    <td>
                       <textarea name="content" id="content" style="width:800px;height:400px;visibility:hidden;">{{$data['content']}}</textarea> 
                    </td>
                </tr>
                <tr>
                    <th>售后服务</th>
                    <td>
                       <textarea name="service" id="service" style="width:800px;height:400px;visibility:hidden;">{{$data['service']}}</textarea> 
                    </td>
                </tr>
            </table>
        </div>
        <!-- 商品详情end -->
    </div>
</div>
<!-- 面板切换结束 -->
<div>
    <td colspan="2">
        <button class="hd-btn hd-btn-primary">提交</button>
    </td>
</div>
</form>
</body>
<script type="text/javascript">
    // 点击按钮就往下新增一层
    function addPic(obj)
    {
        var table = $(obj).parents('table').eq(0);
        var tr = '<tr>';
        tr += "<td style='height:40px'>";
        tr += '<input type="file" name="pics[]" style="display:inline-block">&nbsp;';
        tr += '<button type="button" onclick="removePic(this)" style="display:inline-block;box-shadow: 0 0 5px #ccc;border-radius: 0;font-weight: bold;padding:6px 12px;" class="btn btn-info">－</button></td></tr>';
        table.append(tr);
    }

    // 点击按钮就移除一个是上传框
    function removePic(obj)
    {
        $(obj).parents('tr').eq(0).remove();
    }

    //删除图片异步
    function delPic(id)
    {
        $.get('index.php?m=Admin&c=Pics&a=del',{id:id},function(data){
            if (data.code==0) 
            {
                $('#picLi'+id).remove();
            }else{
                alert(data.message);
            }
        },'json');
    }
</script>
<script type="text/javascript">
    // 找到指定id生成编辑器
    KindEditor.ready(function(K) {
        window.editor = K.create('#content');
        window.editor = K.create('#service');
    });
</script>
<script type="text/javascript">
    $(function(){
        $('.picLi').hover(function(){
            $(this).find('#liDel').stop().animate({'position': 'absolute','top':'0px','transition':'4s all ease'});
        },function(){
            $(this).find('#liDel').stop().animate({'position': 'absolute','top':'-100px','transition':'1s all ease'});
        })
    })
</script>

<script type="text/javascript">
//按照类型抽取对应的属性列表
    function editAttrList(obj)
    {
        var type_id = $(obj).val();
        var goods_id = {{$data['goods_id']}};
        $.get('index.php?m=Admin&c=Goods&a=editAttrList',
            {goods_id:goods_id,type_id:type_id},
            function(data){
                $("#attr_list").html(data);
        });
    }
</script>
<script>
  //加载商品属性
  // var typeid= "{{$data['type_id']}}";
  // var obj = $("[name=type_id]").find("[value="+typeid+"]").attr('selected',true);
  // //直接将对象值赋给方法
  // editAttrList(obj);
  var obj = $('[name=type_id]').find('option:selected').val();
  alert(obj);
</script>
<script>
function addGoodsPrice(obj)
{
    //复制tr行
    var tr = $(obj).parents('tr').eq(0).clone();
    tr.find('span').attr('onclick','removeGoodsAttr(this)').html('-');
    //插入行原tr行后面
    $(obj).parents('tr').eq(0).after(tr.find('[name*=add_price]').val(0).end());
}
function removeGoodsAttr(obj)
{
    $(obj).parents('tr').eq(0).remove();
}
</script>
</html>
